<?php

use app\common\service\Attach;
use think\facade\Route;

/* 分类公共路由 */
Route::group('category', function () {
    Route::get('tree$', 'getCategoryTree');       // 分类树
    Route::get('top', 'getTopCategory');       // 分类树
})->prefix('\app\common\service\Common@')->middleware(['\app\common\middleware\Init']);

// 首页
Route::group('home', function () {
    Route::get('$', 'index');
    Route::get('template', 'template');
    Route::get('template/catecourse', 'cateCourse');

})->prefix('\app\common\service\Home@')
    ->middleware([
        '\app\common\middleware\Init',
        '\app\common\middleware\WithoutLogin',
        '\app\common\middleware\BindLoginUser'
    ]);

// 分享
Route::group('share', function () {
    Route::get('info', '@shareInfo');
    Route::get('signature', '@shareSignature');
})->prefix('\app\common\service\Common')->middleware([
    '\app\common\middleware\Init',
    '\app\common\middleware\WithoutLogin',
    '\app\common\middleware\BindLoginUser'
]);

// 设备登录
Route::group('ioslogin', function () {
    Route::post('$', '@ioslogin');       // 登录
    Route::post('bind$', '@iosloginBind');   // 绑定
})
    ->prefix('\app\common\service\Common')
    ->middleware([
        '\app\common\middleware\Init',
        '\app\common\middleware\WithoutLogin',
        '\app\common\middleware\BindLoginUser'
    ]);

/** 默认跟路由 */
Route::any('/', function () {
    return json([
        'service_info'   => 'Api server',
        'server_name'    => request()->domain(),
        'request_method' => request()->method(),
        'server_time'    => date('Y-m-d H:i:s', request()->time())
    ]);
});

/** 附件相关 */
Route::group('attach', function () {
    Route::get('<filecode>', '@view')->pattern(['filecode' => '[\d\w]+']);
    Route::get('<attach_id>/view/url', '@getViewUrl')->pattern(['attach_id' => '\d+']);
    Route::get('fileurl/<attach_id>', '@getFileUrl')->pattern(['attach_id' => '\d+']);
})->prefix(Attach::class);

Route::group('test', function () {
    // Route::get('queueTuan', '@queueTuan')->setOption('is_api', 0);
})->prefix('\app\common\service\Common');
